package com.client.koshercook.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;

public class ImageLink extends Composite{
	
	/** create a new image link for the outer site with the given link */
	public ImageLink(final String link, final String recipeName){
		final Image m = new Image();
		m.setTitle(link);
		//kipa link
		if(link.startsWith("http://www.kipa")){
			m.setUrl("kipa.gif");
			m.addMouseOverHandler(new MouseOverHandler(){
				public void onMouseOver(MouseOverEvent event) {
					m.setUrl("kipa_inv.gif");
				}
			});
			m.addMouseOutHandler(new MouseOutHandler(){
				public void onMouseOut(MouseOutEvent event) {
					m.setUrl("kipa.gif");
				}
			});
		}
		//chef-lavan link
		else if(link.startsWith("http://www.chef-lavan")){
			m.setUrl("chef-lavan.gif");
			m.addMouseOverHandler(new MouseOverHandler(){
				public void onMouseOver(MouseOverEvent event) {
					m.setUrl("chef-lavan_inv.gif");
				}
			});
			m.addMouseOutHandler(new MouseOutHandler(){
				public void onMouseOut(MouseOutEvent event) {
					m.setUrl("chef-lavan.gif");
				}
			});
		}
		//rotev link
		else if(link.startsWith("http://www.rotev")){
			m.setUrl("rotev.gif");
			m.addMouseOverHandler(new MouseOverHandler(){
				public void onMouseOver(MouseOverEvent event) {
					m.setUrl("rotev_inv.gif");
				}
			});
			m.addMouseOutHandler(new MouseOutHandler(){
				public void onMouseOut(MouseOutEvent event) {
					m.setUrl("rotev.gif");
				}
			});
		}
		//stybel link
		else if(link.startsWith("http://www.stybel")){
			m.setUrl("stybel.gif");
			m.addMouseOverHandler(new MouseOverHandler(){
				public void onMouseOver(MouseOverEvent event) {
					m.setUrl("stybel_inv.gif");
				}
			});
			m.addMouseOutHandler(new MouseOutHandler(){
				public void onMouseOut(MouseOutEvent event) {
					m.setUrl("stybel.gif");
				}
			});
		}
		//matkon-kasher link
		else if(link.startsWith("matkonkasher")){
			m.setUrl("matkonkasher.gif");
			m.addMouseOverHandler(new MouseOverHandler(){
				public void onMouseOver(MouseOverEvent event) {
					m.setUrl("matkonkasher_inv.gif");
				}
			});
			m.addMouseOutHandler(new MouseOutHandler(){
				public void onMouseOut(MouseOutEvent event) {
					m.setUrl("matkonkasher.gif");
				}
			});
		}
		//other link
		else{
			m.setUrl("star_full.gif");
		}
		//set what happens when user clicks image
		//our site
		if(link.startsWith("matkonkasher")){
			m.addClickHandler(new ClickHandler(){
				public void onClick(ClickEvent event) {
					Client.model.setRecipeInfoPanelRecipe(link, recipeName);
				}
			});
		}
		//outer site
		else{
			m.addClickHandler(new ClickHandler(){
				public void onClick(ClickEvent event) {
					Window.open(link, "_blank", "");
				}
			});
		}
		initWidget(m);
	}
}
